{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,11):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "黑暗正义联盟：天启星战争 马特·皮特斯,Christina,Sotta\n",
      "天雷地火3回收大战 Michael,Schroeder\n",
      "第五惑星 沃尔夫冈·彼德森\n",
      "最终剪接 Omar,Naim\n",
      "触发点 James,McDonagh\n",
      "异星绑架 马蒂·贝克曼\n",
      "太空炮弹 梅尔·布鲁克斯\n",
      "激战星河 克里斯·罗伯茨\n",
      "鲨卷风5：全球鲨暴 安东尼·C·费兰特\n",
      "鲨人种儿 Paul,Ziller\n",
      "决战猩球1973 J·李·汤普森\n",
      "暗夜呢喃 Sean,Branney\n",
      "小精灵续集 乔·丹特\n",
      "清醒梦 金俊诚\n",
      "科学怪人的新娘 詹姆斯·惠尔\n",
      "切尔诺贝利·禁区电影版 结局二 德米特里·基谢廖夫\n",
      "末日哲学家 约翰·赫德斯\n",
      "飞天猴子 Robert,Grasmere\n",
      "杜立巴 Wayne,Slaten\n",
      "逆流的色彩 什恩·卡鲁斯\n",
      "抗体 布兰登·柯南伯格\n",
      "欧罗巴报告 塞巴斯特·柯代洛\n",
      "光晕4.航向黎明号 斯特瓦特·亨德尔\n",
      "比邻星 艾丽斯·威诺古尔\n",
      "云图2012 汤姆·提克威,拉娜·沃卓斯基,莉莉·沃卓斯基\n",
      "记忆提取 尼尔·帕尼瑞\n",
      "超人钢铁之躯 扎克·施奈德\n",
      "白金数据 大友启史\n",
      "巨变之后：人口为零 Steve,Broster\n",
      "坦克女郎 瑞秋·塔拉蕾\n",
      "赐予者 菲利普·诺伊斯,\n",
      "外星人保罗 格雷格·莫托拉\n",
      "俄罗斯大厦 弗雷德·谢皮西\n",
      "机器闹鬼 瑞秋·塔拉蕾\n",
      "纸上谋杀 Tushar,Raheja\n",
      "龙桥 Isaac,Florentine\n",
      "威廉泽罗的重建 丹·布什\n",
      "生态箱 罗根·费纳根\n",
      "劫后余生2008 Steve,Broster\n",
      "恐怖狗狗 罗伯特·文斯\n",
      "安全没有保障 科林·特雷沃罗\n",
      "喋血战士 戴夫·威尔逊\n",
      "机器人战争：人类末日 Scott,Wheeler\n",
      "游戏学院 马修·阿诺德,,Brandon,Laatsch\n",
      "无处逃生 Neil,Mcenery-West\n",
      "心慌方2：超立方体 安德列·塞库拉\n",
      "第三封信 Grzegorz,Jonkajtys\n",
      "最后的德鲁伊：加尔姆战争 押井守\n",
      "黑镜圣诞特辑白色圣诞 卡尔·蒂贝茨\n",
      "极度空间1988 约翰·卡朋特\n",
      "异界 尼基塔·阿格诺夫\n",
      "天龙号醒来之返航迷途 西门\n",
      "零号基地 Andree,Wallin\n",
      "星际之门：真理之盒 罗伯特·C·库珀\n",
      "星际之门：时空连续 Martin,Wood\n",
      "唯一 Takashi,Doscher\n",
      "唯一2020 Takashi,Doscher\n",
      "巨型蜘蛛2013 蒂波尔·塔卡克斯\n",
      "饥饿站台 Galder,Gaztelu-Urrutia\n",
      "系列怪兽区 加拉斯 小串遼太郎\n",
      "莫斯科陷落2 费奥多尔·邦达尔丘克\n",
      "时光穿梭 Bradley,King\n",
      "星球大战9：天行者崛起 J·J·艾布拉姆斯\n",
      "虚拟性成瘾 Benjamin,Dickinson\n",
      "星河战队3 Edward,Neumeier\n",
      "星河战队2 菲尔,蒂贝特\n",
      "断头谷1999 蒂姆·波顿\n",
      "阿尔法测试 Aaron,Mirtes\n",
      "宇宙铁人剧场版 竹本弘一,佐伯孚治,若林幹,小西通雄,神野智,折田至,村山新治\n",
      "纳尼亚传奇1：狮子、女巫、魔衣柜 安德鲁·亚当森\n",
      "星球绿巨人 Greg,Pak\n",
      "我是人类 Elena,Gaby,塔琳·萨瑟恩\n",
      "世界之战2005 史蒂文·斯皮尔伯格\n",
      "侏罗纪雷霆 Milko,Davis,Thomas,Martwick\n",
      "星际之旅：奥德赛 Jon,Bonnell\n",
      "晶兵总动员 乔·丹特\n",
      "ARI历险记：我的机器人朋友 Stephen,Shimek\n",
      "切尔诺贝利·禁区电影版 未知\n",
      "玉子 奉俊昊\n",
      "时间裂缝 Tom,Holland\n",
      "时空穿越者2018 Svend,Ploug,Johansen\n",
      "生死调频 格里高利·霍布里特\n",
      "灵幻夹克 约翰·梅布里\n",
      "超神 加布里埃尔·马斯卡罗\n",
      "超自然战场 Tom,Chaney\n",
      "形成 奥玛尔·内姆\n",
      "黑色尾流 Jeremiah,Kipp\n",
      "情迷步话机 金正权\n",
      "九度空间 约翰·奥古斯特\n",
      "异星怪兽之荒野求生 宁静,李乐\n",
      "日本沉没 樋口真嗣\n",
      "尾流场计划 L.A.,Lopes\n",
      "黑魔王 雷德利·斯科特\n",
      "地球最末日 阿贝尔·费拉拉\n",
      "洛杉矶之战(原声版) 乔纳森·里贝斯曼\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "import re\n",
    "import pymysql\n",
    "\n",
    "class connsql():\n",
    "    def __init__(self):\n",
    "        \n",
    "        self.conn=pymysql.connect(host='127.0.0.1',user='root',password='1234',database='myschool',charset='gbk')\n",
    "        \n",
    "       \n",
    "global headers\n",
    "headers={\n",
    "    \"User-Agent\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763\"\n",
    "}\n",
    "urls=['http://www.sztoyota.com/vodsearch/class/%E7%A7%91%E5%B9%BB%E7%89%87/nid/1/page/{}/sid/1.html'.format(i) for i in range(1,20)]\n",
    "def get_titles(urls,data=None):\n",
    "    web_data=requests.get(urls,headers=headers)\n",
    "    web_data.encoding='utf-8'\n",
    "    html=web_data.text\n",
    "    res=re.findall('<h2><a target=\"_blank\" href=.*?>(.*?)</a></h2>.*?导演:</em>(.*?)</p>',html,re.S)\n",
    "    \n",
    "    conn=connsql()\n",
    "    \n",
    "    conn=conn.conn\n",
    "    cursor=conn.cursor()\n",
    "    for res in res:\n",
    "        print(res[0],res[1])\n",
    "        sql='insert into movies(name,dname) values(\"%s\",\"%s\")'%(res[0],res[1])\n",
    "        cursor.execute(sql)\n",
    "        conn.commit()\n",
    "        \n",
    "for url in urls:\n",
    "    get_titles(url)\n",
    "\n",
    "        \n",
    "        \n",
    "\n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
